{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##\n",
    "\n",
    ">* list方法/函数 的所有的使用场景及案例，方法如：\n",
    ">> 1. append()\n",
    ">> 2. pop(index)\\remove(values)\n",
    ">> 3. count()\n",
    ">> 4. index()\n",
    ">> 5. extend()\n",
    ">> 6. sort()\n",
    ">> ...\n",
    "> * list高级用法 如：\n",
    ">> 1.copy()  复制不等于赋值\n",
    ">> 2.enu\n",
    "> * 课本练习（课堂上带大家做了）Don't panic==>on tap,其中知识点:\n",
    ">>. 1.list的一些方法实现\n",
    ">>. 2.str=> list 的方法 list(str)\n",
    ">>. 3.list =>str 的方法''join(list)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 本周内容\n",
    "### 先来做一些简单的练习\n",
    "\n",
    "* 1.vowels2.py\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "i\n",
      "i\n",
      "a\n"
     ]
    }
   ],
   "source": [
    "vowels = ['a','e','i','o','u'] # 这是元音(list)\n",
    "word = \"Milliways\"# 这是文本(str)\n",
    "# 需求: word中出现的vowels 打印出来\n",
    "for letter in word: # letter 可以随便命名，不会影响我们的结果\n",
    "                    # 一班情况下，item（内容）=>简写：i\n",
    "#    print(letter)\n",
    "   if letter in vowels:\n",
    "        print(letter)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['i', 'a']"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# append()经常用于新建列表\n",
    "found=[]\n",
    "for letter in word:\n",
    "    if letter in vowels:\n",
    "        if letter not in found:\n",
    "            found.append(letter)\n",
    "found"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid syntax (<ipython-input-11-a3fbc8007032>, line 13)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m\"<ipython-input-11-a3fbc8007032>\"\u001b[1;36m, line \u001b[1;32m13\u001b[0m\n\u001b[1;33m    Alipay =  int input(\"请输入您的支付宝余额：\")\u001b[0m\n\u001b[1;37m                  ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
     ]
    }
   ],
   "source": [
    "# 准备工作\n",
    "# 1.商品信息\n",
    "goods_list = [\n",
    "   [\"python课本\",60],\n",
    "   [\"华为手机\",8000],\n",
    "   [\"小米手环\",199],\n",
    "  [\"蜜雪冰城奶茶\",8]\n",
    "             ]\n",
    "    \n",
    "# 2.用户购物信息\n",
    "user_shopping_list = []\n",
    "# 用户输入（余额）：  #----知识点：打印与用户输入----\n",
    "Alipay =  int input(\"请输入您的支付宝余额：\")\n",
    "info = '''-------goods detail-------\n",
    "编号0，商品名称：%s，商品价格：%s元\n",
    "编号1，商品名称：%s，商品价格：%s元\n",
    "编号2，商品名称：%s，商品价格：%s元\n",
    "编号3，商品名称：%s，商品价格：%s元\n",
    "'''%(good_list[0][0],good_list[0][1],\n",
    "    good_list[1][0],good_list[1][1],\n",
    "    good_list[2][0],good_list[2][1],\n",
    "    good_list[3][0],good_list[3][1]),\n",
    "print(info)\n",
    "\n",
    "# 是不是应该循环了呢？\n",
    " print(\"-------goods detail-------\")\n",
    "for i in range(4):# i 是0,1,2,3\n",
    "    print(\"编号%s，商品名称：%s，商品价格：%s元\"%\n",
    "         %(i,good_list[i][0],good_list[i][1]))\n",
    "##用户输入商品编号\n",
    "chioce =int input(\"请输入购买商品的编号:\")\n",
    "## 1.输入的编号存在，判断余额是否够\n",
    "if chioce < len(good_list):\n",
    "    if good_list[chioce][1]<Alipay:\n",
    "        Alipay = Alipay-good_list[chioce][1]\n",
    "        user_shopping_list.append(good_list[chioce][1])\n",
    "        print(\"您的商品购买成功，已添加到购物车，您的余额还有%s\"%(Alipay))\n",
    "    else:\n",
    "        print(\"您的余额不足，请用花呗试试看？\")\n",
    " ### 1.余额够，用户余额-商品价格   \n",
    "  ### 2.余额不够，“您的余额不足”\n",
    "else:\n",
    "    print(\"您输入的商品编号可能超过我们的商品范围或者不存在这个商品\")\n",
    "## 2.输入的编号不存在，“请输入正确的余额”  \n",
    "# 1.输入正确，打印商品列表\n",
    "\n",
    "##用户输入商品编号\n",
    "## 1.输入的编号存在，判断余额是否够\n",
    "### 1.余额够，用户余额-商品价格\n",
    "### 2.余额不够，“您的余额不足”\n",
    "## 2.输入的编号不存在，“请输入正确的余额”\n",
    "# 2.输入错误，“请输入正确的余额”\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
